//
//  FirstViewController.m
//  UI_Homework_09
//
//  Created by 黄威 on 16/5/13.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "FirstViewController.h"
#import "MessageChildViewController.h"
#import "ChatChildViewController.h"
@interface FirstViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (nonatomic,retain)MessageChildViewController *childmessage;
@property (nonatomic,retain)ChatChildViewController *childchat;
@property (nonatomic,retain)UISegmentedControl *segement;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    [self create];
    
    
    
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.segement = [[UISegmentedControl alloc] initWithItems:@[@"消息", @"通话"]];
    self.segement.selectedSegmentIndex = 1;
    
    
    [self.segement addTarget:self action:@selector(handleSeg:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = self.segement;
    
    
    self.childmessage = [[MessageChildViewController alloc] init];
    self.childmessage.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"3"]];
    image.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    
    
    
    [self.view addSubview:image];
    
    
    self.childchat = [[ChatChildViewController alloc] init];
    self.childchat.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    
    UIImageView *image2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"333"]];
    image2.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    
    [self.view addSubview:image2];
    
    image.tag = 10000;
    image2.tag = 20000;
    
    
   
}


- (void)handleSeg:(UISegmentedControl *)seg {
    
    if (seg.selectedSegmentIndex == 0) {
        
        [self.view sendSubviewToBack:[self.view viewWithTag:20000]];
    }else{
    
     [self.view sendSubviewToBack:[self.view viewWithTag:10000]];
    
    }

}


- (void)create{
    self.view.backgroundColor = [UIColor redColor];

   self.navigationItem.title = @"首页";

    self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"消息.png"] tag:1000 ];
   
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"touxiang.png"] style:UIBarButtonItemStylePlain target:self action:@selector(handle)];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"点我" style:UIBarButtonItemStylePlain target:self action:@selector(dianwoya)];
   
    
}


- (void)dianwoya{



    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Rootkits" message:@"让你点" delegate:self cancelButtonTitle:@"放弃治疗" otherButtonTitles:  nil];
    
    
    [alert show];



}

- (void)handle{

    UIImagePickerController *pick = [[UIImagePickerController alloc]init];

    pick.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
    pick.editing = YES;
    pick.allowsEditing = YES;
    pick.delegate = self;

   [ self presentViewController:pick animated:YES completion:^{
        
    }];
    
    
    

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
    
   
    
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    UIBarButtonItem *aaa = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(handle)];
    

    
    self.navigationItem.leftBarButtonItem = aaa;



}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
